package com.sgchen.demo.controller;


import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson2.JSONObject;
import com.sgchen.demo.config.AjaxResult;
import com.sgchen.demo.entity.po.AccountPo;
import com.sgchen.demo.entity.po.ChildAccountPo;
import com.sgchen.demo.service.AccountService;
import com.sgchen.security.annotation.*;
import com.sgchen.security.config.SecretConfig;
import com.sgchen.security.enums.DesensitizedMode;
import com.sgchen.security.handler.CryptoTableHandler;
import com.sgchen.security.util.CryptoAsymmetricUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sgchen
 * @date 2024/2/6 11:37
 */
@RestController
@RequestMapping("test")
@EncryptController(
        value = {
                @DesensitizedUnit(field = "secondPhone", mode = DesensitizedMode.mobile),
                @DesensitizedUnit(field = "secondReceiver", mode = DesensitizedMode.name),
                @DesensitizedUnit(field = "auditor", mode = DesensitizedMode.name),
                @DesensitizedUnit(field = "secondAddress", mode = DesensitizedMode.address),
                @DesensitizedUnit(field = "userAccount", mode = DesensitizedMode.mobile)
        },
        decryptField = {
                @ReqDecryptField(field = "account"),
                @ReqDecryptField(field = "userName"),
                @ReqDecryptField(field = "test")
        }
)
public class TestController {

    @DesensitizedMethod({
            @DesensitizedUnit(field = "secondPhone", mode = DesensitizedMode.mobile),
            @DesensitizedUnit(field = "secondReceiver", mode = DesensitizedMode.name),
            @DesensitizedUnit(field = "auditor", mode = DesensitizedMode.name),
            @DesensitizedUnit(field = "secondAddress", mode = DesensitizedMode.address),
            @DesensitizedUnit(field = "userAccount", mode = DesensitizedMode.mobile)
    })
    @PostMapping("/getInfo")
    public AjaxResult getInfo(@RequestBody AccountPo accountPo) {
        System.out.println(JSONObject.toJSONString(accountPo));
        return AjaxResult.success(accountPo);
    }

}